import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { SMiniGuildInfo } from "../../../../Message/Game/SMiniGuildInfo";
import { GuildConfig } from "../../resource/GuildConfig";
import { GuildRoomIcon } from "./myGuild/GuildRoomIcon";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { ColorConfig } from "../../resource/ColorConfig";
import { EVIPType } from "../../../../Message/Public/EVIPType";
import { GuildController } from "../../control/GuildController";
import { GuildShowType } from "./GuildShowType";
import { Cache } from "../../cache/Cache";
import { Language } from "../../../../extend/language/Language";
import { GuildVipItem } from "./GuildVipItem";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { GButton } from "../../../../com/mui/controls/GButton";
import { ImagesConst } from "../../resource/ImagesConst";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
type int = number;
//class GuildRender
    
    export  class GuildRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=0;
            super.data = arg1;
            this._sMiniGuildInfo = arg1 as SMiniGuildInfo;
            if (this._sMiniGuildInfo) 
            {
                this._vip = this._sMiniGuildInfo.leaderVIP;
                loc1 = GuildConfig.instance.getMaxNumByLevel(this._sMiniGuildInfo.level);
                this.rankTxt.text = this._sMiniGuildInfo.rank.toString();
                if (this._sMiniGuildInfo.house > 0) 
                {
                    if (this._roomIcon == null) 
                    {
                        this._roomIcon = new GuildRoomIcon();
                        this._roomIcon.x = 60;
                        this._roomIcon.y = 0;
                    }
                    if (!this.contains(this._roomIcon)) 
                    {
                        this.addChild(this._roomIcon);
                    }
                    this._roomIcon.level = this._sMiniGuildInfo.house;
                }
                else if (this._roomIcon && this.contains(this._roomIcon)) 
                {
                    this.removeChild(this._roomIcon);
                }
                this.nameTxt.text = this._sMiniGuildInfo.guildName;
                this.campTxt.htmlText = HTMLUtil.addColor(GameDefConfig.instance.getECamp(this._sMiniGuildInfo.camp), ColorConfig.instance.getCampColor(this._sMiniGuildInfo.camp).color);
                this.chairmanTxt.text = this._sMiniGuildInfo.leaderName;
                this._vipItem.vip = this._vip;
                if (this._vip != EVIPType._EVIPTypeNormal) 
                {
                    this._noVipTxt.visible = false;
                }
                else 
                {
                    this._noVipTxt.visible = true;
                }
                this.levelTxt.text = this._sMiniGuildInfo.level.toString();
                this.numberTxt.text = this._sMiniGuildInfo.playerNum.toString() + "/" + this._sMiniGuildInfo.maxPlayerNum.toString();
                if (GuildController.curShowType != GuildShowType.NormalGuildList) 
                {
                    this.seeBtn.move(550, 0);
                }
                else 
                {
                    if (this._sMiniGuildInfo.camp == Cache.instance.role.entityInfo.camp) 
                    {
                        if (this._sMiniGuildInfo.apply) 
                        {
                            this.operBtn.label = Language.getString(57025);
                            this.operBtn.name = "cancelApply";
                        }
                        else 
                        {
                            this.operBtn.label = Language.getString(57026);
                            this.operBtn.name = "apply";
                        }
                        this.operBtn.drawNow();
                        this.addChild(this.operBtn);
                    }
                    else if (this.operBtn && this.contains(this.operBtn)) 
                    {
                        this.removeChild(this.operBtn);
                    }
                    this.seeBtn.move(590, 0);
                }
                this.selectMyGuild();
            }
            return;
        }

        /* internal  */init(): void
        {
            var loc1=11661567;
            this.rankTxt = new Object /* flash.text.TextField */();
            this.rankTxt.x = 10;
            this.rankTxt.y = 0;
            this.rankTxt.height = 30;
            this.rankTxt.selectable = false;
            this.rankTxt.textColor = loc1;
            this.rankTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            addChild(this.rankTxt);
            this.nameTxt = new Object /* flash.text.TextField */();
            this.nameTxt.x = 50;
            this.nameTxt.y = 0;
            this.nameTxt.height = 30;
            this.nameTxt.selectable = false;
            this.nameTxt.textColor = loc1;
            addChild(this.nameTxt);
            this.campTxt = new Object /* flash.text.TextField */();
            this.campTxt.x = 155;
            this.campTxt.y = 0;
            this.campTxt.height = 30;
            this.campTxt.selectable = false;
            this.campTxt.textColor = loc1;
            this.campTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            addChild(this.campTxt);
            this._vipItem = new GuildVipItem();
            this._vipItem.x = 280;
            this._vipItem.y = 3;
            this.addChild(this._vipItem);
            this._noVipTxt = ObjCreate.createTextField(Language.getString(30085), 280, 3, 220, 20, this, GlobalStyle.textFormat6);
            this.chairmanTxt = new Object /* flash.text.TextField */();
            this.chairmanTxt.x = 320;
            this.chairmanTxt.y = 0;
            this.chairmanTxt.height = 30;
            this.chairmanTxt.selectable = false;
            this.chairmanTxt.textColor = loc1;
            addChild(this.chairmanTxt);
            this.levelTxt = new Object /* flash.text.TextField */();
            this.levelTxt.x = 305;
            this.levelTxt.y = 0;
            this.levelTxt.height = 30;
            this.levelTxt.width = 35;
            this.levelTxt.selectable = false;
            this.levelTxt.textColor = loc1;
            this.levelTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            addChild(this.levelTxt);
            this.numberTxt = new Object /* flash.text.TextField */();
            this.numberTxt.x = 352;
            this.numberTxt.y = 0;
            this.numberTxt.height = 30;
            this.numberTxt.width = 60;
            this.numberTxt.selectable = false;
            this.numberTxt.textColor = loc1;
            this.numberTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            addChild(this.numberTxt);
            this.seeBtn = new GButton();
            this.seeBtn.label = Language.getString(57027);
            this.seeBtn.styleName = "Button";
            this.seeBtn.move(470, 0);
            this.seeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onSeeBtnClickHandler);
            addChild(this.seeBtn);
            this.line = ObjCreate.createBg(10, 25, 505, 2, this, ImagesConst.SplitLine);
            if (GuildController.curShowType != GuildShowType.NormalGuildList) 
            {
                this.line.width = 630;
                this.seeBtn.setSize(70, 24);
            }
            else 
            {
                this.operBtn = new GButton();
                this.operBtn.styleName = "Button";
                this.operBtn.setSize(67, 24);
                this.operBtn.move(520, 0);
                this.operBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOperBtnClickHandler);
                this.line.width = 650;
                this.seeBtn.setSize(60, 24);
            }
            this.seeBtn.drawNow();
            this.downLine = new Object /* flash.display.Sprite */();
            this.downLine.mouseEnabled = false;
            this.downLine.graphics.beginFill(3368499, 1);
            this.downLine.graphics.lineStyle(2, 16744192, 0);
            this.downLine.graphics.drawRoundRect(1, 0, width, height, 6, 6);
            this.downLine.graphics.endFill();
            this.downLine.cacheAsBitmap = true;
            this.resetPos();
            return;
        }

        /* internal  */onOperBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this.operBtn.name != "apply") 
            {
                if (this.operBtn.name == "cancelApply") 
                {
                    this.operBtn.name = "apply";
                    this.operBtn.label = Language.getString(57026);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuildCancelApply, {"guildId": this._sMiniGuildInfo.guildId}));
                }
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildApply, {"guildId": this._sMiniGuildInfo.guildId}));
            }
            return;
        }

        /* internal  */onSeeBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildInfoWindowOpen, this._sMiniGuildInfo.guildId));
            return;
        }

        /* internal  */selectMyGuild(): void
        {
            var loc1=Cache.instance.guild.myGuildInfo;
            if (loc1 && this._sMiniGuildInfo && loc1.guildId == this._sMiniGuildInfo.guildId) 
            {
                this.downLine.x = 10;
                addChildAt(this.downLine, 0);
            }
            else if (this.downLine.parent) 
            {
                removeChild(this.downLine);
            }
            return;
        }

        /* internal  */resetPos(): void
        {
            this.rankTxt.x = 35;
            this.nameTxt.x = 80;
            this.nameTxt.width = 105;
            this.nameTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this.campTxt.x = 210;
            this.chairmanTxt.x = 320;
            this.chairmanTxt.width = 105;
            this.chairmanTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this.levelTxt.x = 410;
            this.numberTxt.x = 477;
            this.seeBtn.move(550, 0);
            return;
        }

        /* internal */ /* var */rankTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_roomIcon: GuildRoomIcon;

        /* internal */ /* var */nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */campTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_vipItem: GuildVipItem;

        /* internal */ /* var */_noVipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */chairmanTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */levelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */numberTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */operBtn: GButton;

        /* internal */ /* var */seeBtn: GButton;

        /* internal */ /* var */line: Object /* flash.display.Bitmap */;

        /* internal */ /* var */downLine: Object /* flash.display.Sprite */;

        /* internal */ /* var */_sMiniGuildInfo: SMiniGuildInfo;

        /* internal */ /* var */_vip: int;
    }
